home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 19 / CU Amiga Magazine's Super CD-ROM 19 (1998)(EMAP Images)(GB)[!][issue 1998-02].iso / CUCD / Online / NNTPd / server / nextlast.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-11-01  |  1.9 KB  |  90 lines

  1. #ifndef lint
  2. static char    sccsid[] = "@(#)$Id: nextlast.c,v 1.8 1994/11/01 06:08:21 sob Exp sob $";
  3. #endif
  4.  
  5. #include "common.h"
  6.  
  7. /*
  8.  * NEXT
  9.  * LAST
  10.  *
  11.  * Retrieve the message-id of the next or last article in the
  12.  * newsgroup.  Position the current article pointer to this
  13.  * article.
  14.  */
  15.  
  16. void
  17. nextlast(argc, argv)
  18.     int    argc;
  19.     char    *argv[];
  20. {
  21.     char    artbuf[MAXPATHLEN], art_id[MAXBUFLEN];
  22.     int    oldptr;
  23.     int    next;
  24.  
  25.     if (!canread) {
  26.         printf("%d You only have permission to transfer, sorry.\r\n",
  27.             ERR_ACCESS);
  28.         (void) fflush(stdout);
  29.         return;
  30.     }
  31.  
  32.     if (!ingroup) {
  33.         printf("%d You are not currently in a newsgroup.\r\n",
  34.             ERR_NCING);
  35.         (void) fflush(stdout);
  36.         return;
  37.     }
  38.  
  39.     if (argc != 1) {
  40.         printf("%d NEXT/LAST need no arguments.\r\n", ERR_CMDSYN);
  41.         (void) fflush(stdout);
  42.         return;
  43.     }
  44.  
  45.     next = (argv[0][0] == 'n' || argv[0][0] == 'N');
  46.  
  47.     if (art_ptr < 0 || art_ptr >= num_arts) {
  48.         printf("%d No current article selected.\r\n",
  49.             ERR_NOCRNT);
  50.         (void) fflush(stdout);
  51.         return;
  52.     }
  53.  
  54.     if (next ? (art_ptr + 1 >= num_arts) : (art_ptr - 1 < 0)) {
  55.         printf("%d No %s article to retrieve.\r\n",
  56.         next ? ERR_NONEXT : ERR_NOPREV,  next ? "next" : "previous");
  57.         (void) fflush(stdout);
  58.         return;
  59.     }
  60.  
  61.     oldptr = art_ptr;
  62.     (void) sprintf(artbuf, "%d", art_array[next ? ++art_ptr : --art_ptr]);
  63.  
  64.     if (!valid_art(artbuf)) {
  65.         printf("%d Invalid article number: %s.\r\n", ERR_NOARTIG,
  66.             artbuf);
  67.         (void) fflush(stdout);
  68.         return;
  69.     }
  70.  
  71.     while (open_valid_art(artbuf, art_id) == NULL) {
  72.         if (((next) ? (++art_ptr >= num_arts) : (--art_ptr < 0))) {
  73.             printf("%d No %s article to retrieve.\r\n",
  74.                 next ? ERR_NONEXT : ERR_NOPREV,
  75.                 next ? "next" : "previous");
  76.             art_ptr = oldptr;
  77.             (void) fflush(stdout);
  78.             return;
  79.         }
  80.         (void) sprintf(artbuf, "%d", art_array[art_ptr]);
  81.     }
  82.  
  83.     printf("%d %s %s Article retrieved; request text separately.\r\n",
  84.         OK_NOTEXT, artbuf, art_id);
  85.  
  86.     if (argc > 1)
  87.         art_ptr = findart(artbuf);
  88.     (void) fflush(stdout);
  89. }
  90.